$(function () {
  $("form").validate({
    errorPlacement: function (error, element) {
      $(element).parents().find(".eron").children().text("")
      $(element).parents().find(".eron").append(error);
    },
    errorElement: "span",
    success: function (lable) {
    },
    rules: {
      uname: {
        required: true,
      },
      upwd: {
        required: true,
      }
    },
    messages: {
      uname: {
        required: "用户名必填",
      },
      upwd: {
        required: "密码必填",
      }
    },
    submitHandler() {

      $.ajax({
        url: "./account/login",
        type: "post",
        data: $("form").serialize()//前端发送到服务器的数据 data
      }).then(function (response) { //服务器响应到前端的数据 response

        if (response.status == 200) {
          layer.msg("登录成功");
          console.log(response.data)
          //把登录成功的 用户信息,保存到浏览器的本地存储
          localStorage.setItem("userinfo",JSON.stringify(response.data))

          console.log(localStorage.setItem("userinfo", JSON.stringify(response.data)));
          setTimeout(function () {
            location = "index.html";
          }, 1000)
        } else {
          layer.msg("登录失败,用户名或密码错误!");
        }
      })
      return false;
    }
  })

  $(".reg_foot").on("click",function () {
      location = "register.html"
  })
})